#include<stdio.h>
#include<stdlib.h>
struct stu
{
	char name[11];
	char arr[11];
	int score;
};
typedef struct lnode
{
	struct stu data;
	struct lnode* next;
}lnode,*linklist;
int main()
{
	linklist newnode, phead;
	phead = (linklist)malloc(sizeof(lnode));
	newnode = phead;
	phead->next = NULL;
	int count;
	int best=0;
	int worst=100;
	scanf("%d", &count);
	linklist pbest=NULL, pworst=NULL;
	for (int i = 0; i < count; i++)
	{
		linklist p = (linklist)malloc(sizeof(lnode));
		scanf("%s", p->data.name);
		scanf("%s", p->data.arr);
		scanf("%d", &p->data.score);
		p->next = NULL;
		newnode->next = p;
		newnode = p;
	}
	linklist j = phead;
	linklist k = phead;
	for (int i = 0; i < count; i++)
	{
		j = j->next;
		if (j->data.score > best)
		{
			best = j->data.score;
			pbest = j;
		}
	}
	for (int i = 0; i < count; i++)
	{
		k = k->next;
		if (k->data.score < worst)
		{
			worst = k->data.score;
			pworst = k;
		}
	}
	printf("%s %s\n", pbest->data.name, pbest->data.arr);
	printf("%s %s\n", pworst->data.name, pworst->data.arr);
	return 0;
}